package com.knight.admin.interceptor;

import org.apache.log4j.Logger;

import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.knight.admin.common.constant.Constant;

public class LoginInterceptor implements Interceptor {

	private static final Logger logger = Logger.getLogger(LoginInterceptor.class);

	@Override
	public void intercept(Invocation inv) {
		// 获取请求url
		String actionKey = inv.getActionKey();
		logger.debug("请求url:" + actionKey);
		if (actionKey.contains("login")) {
			// 如果包含登录url 则直接放行
			inv.invoke();
			return;
		}
		Object sessionAttr = inv.getController().getSessionAttr(Constant.LOGINUSER);
		if (sessionAttr == null) {
			// 没有登录跳转到登录界面
			inv.getController().redirect("/login/loginPage");
			return;
		}
		inv.invoke();
	}

}
